﻿///<summary>
/// Library
///</summary>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OperationLibrary
{
    public class Operation
    {
        /// <summary>
        /// shared with all subclasses
        /// </summary>
        private double _numberA = 0;
        private double _numberB = 0;

        /// <summary>
        /// Number A property
        /// </summary>
        public double NumberA
        {
            get
            {
                return _numberA;
            }
            set
            {
                _numberA = value;
            }
        }

        /// <summary>
        /// Number B Property
        /// </summary>
        public double NumberB
        {
            get
            {
                return _numberB;
            }
            set
            {
                _numberB = value;
            }
        }

        /// <summary>
        /// get the result
        /// this is override for subclass to return their resluts.
        /// </summary>
        public virtual double getResult()
        {
            double result = 0;
            return result;
        }

        /// <summary>
        /// check get in string
        /// </summary>
        public static string checkNumberInput(string currentNumber, string inputString)
        {
            string result = "";
            //Reports the index of the first occurrence of the specified String in this instance.
            if (inputString == ".")
            {
                if (currentNumber.IndexOf(".") < 0)      
                    result = "0" + inputString;
                else
                    result = currentNumber + inputString;
            }
            return result;
        }
    }

    /// <summary> 
    /// Class Operation Add
    /// </summary>
    public class OperationAdd : Operation
    {
        public override double getResult()
        {
            double result = 0;
            result = this.NumberA + this.NumberB;
            return result;
        }
    }

    /// <sumarry>
    /// Class Operation Sub
    /// </summary>
    public class OperationSub : Operation
    {
        public override double getResult()
        {
            double result = 0;
            result = this.NumberA - this.NumberB;
            return result;
        }
    }

    public class OperationMul : Operation
    {
        public override double getResult()
        {
            double result = 0;
            result = this.NumberA * this.NumberB;
            return result;
        }
    }

    public class OperationDiv : Operation
    {
        public override double getResult()
        {
            double result = 0;
            result = this.NumberA / this.NumberB;
            return result;
        }
    }
}
